<template>
    <div>
        <Form :label-width="100" inline>
            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.YWGL007"></area-linkage>
            </Form-item>
            <Form-item label="姓名">
                <Input v-model="queryParam.azcp0003" placeholder="" clearable style="width: 200px"></Input>
            </Form-item>
            <Form-item label="身份证号码">
                <Input v-model="queryParam.azcp0001" placeholder="" clearable style="width: 200px"></Input>
            </Form-item>
            <Row class="button_row">
               <span style="float: left;">
                <Button type="primary" icon="ios-cloud-download-outline" @click="exportExcel" class="button_item_left">
                    导出
                </Button>
               </span>
                <span style="float: right;">
                 <Button type="primary" @click="searchQuery">查询</Button>
                 <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                </span>
            </Row>
        </Form>
        <div class="table_div">
            <Table :columns="columns" :data="tableData" :loading="Loading">
                <template slot-scope="{ row, index  }" slot="action">
                    <Button type="info" size="small" style="margin-right: 5px" @click="handleEdit(index)">编辑</Button>
                    <Button type="success" size="small" style="margin-right: 5px" @click="handleView(index)">详情</Button>
                </template>
            </Table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import DateFormat from '@/plugins/format.js'

    export default {
        mixins: [CommonMixin],
        components: {},
        data() {
            return {
                rules: {
                    cfab0001: [
                        {required: true, message: '信息必填', trigger: 'blur'}
                    ],
                    cfab0002: [
                        {required: true, message: '信息必填', trigger: 'blur'}
                    ],
                    cfab0003: [
                        {required: true, message: '必须是数字类型', trigger: 'blur', type: 'number'}
                    ],
                    cfab0004: [
                        {required: true, message: '必须是数字类型', trigger: 'blur', type: 'number'}
                    ],
                    cfab0005: [
                        {required: true, message: '信息必填', trigger: 'blur', type: 'date'},
                    ],
                    cfab0006: [
                        {required: true, message: '信息必填', trigger: 'blur', type: 'date'},
                    ]
                },
                columns: [
                    {
                        title: '属地',
                        key: 'DEPENDENCY',
                        align: 'center',
                    },
                    {
                        title: '姓名',
                        key: 'AAC003',
                        align: 'center',
                        width: '100px'
                    },
                    {
                        title: '身份证号',
                        key: 'AAE135',
                        align: 'center',
                    },
                    {
                        title: '保障类别',
                        key: 'MZBZZHN',
                        align: 'center',
                        width: '120px'
                    },
                    {
                        title: '保障开始时间',
                        key: 'AAE030',
                        width: '150px',
                        render: (h, params) => {
                            let value = params.row.AAE030
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            } else {
                                value = DateFormat(value, 'YYYY-MM-DD')
                            }
                            return h('span', value + ' ')
                        },
                        align: 'center',
                    },
                    {
                        title: '参保经办时间',
                        key: 'AAE036',
                        width: '150px',
                        render: (h, params) => {
                            let value = params.row.AAE036
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            } else {
                                value = DateFormat(value, 'YYYY-MM-DD')
                            }
                            return h('span', value + ' ')
                        },
                        align: 'center',
                    },
                    {
                        title: '失败原因',
                        key: 'ERROR',
                        align: 'center',
                    }
                ],
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss00004Service/getFailPageList",
                    edit: "/api/ac/subsistence/ss06001Service/updateData",
                    add: "/api/ac/subsistence/ss06001Service/insertData",
                    exportExcel: "/api/ac/subsistence/ss00004Service/exportExcel",
                },
                exportFileName: "医保参保失败数据",
                formData: {
                    cfab0001: '',
                    cfab0002: '',
                    cfab0003: '',
                    cfab0004: '',
                    cfab0005: '',
                    cfab0006: '',
                    cfab0009: '',
                    cfab0010: ''
                },
                queryParam: {},
                visible: false,
                showSubmit: true,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: ""
            }
        },
        methods: {
            handleAdd() {
                let that = this;
                that.title = "保障标准录入"
                let record = {};
                that.visible = true
                that.showSubmit = true
                that.formData = Object.assign({}, record)
            },
            handleEdit(index) {
                let that = this;
                that.title = "保障标准编辑"
                let record = that.tableData[index];
                if (record.id) {
                    that.visible = true
                    that.showSubmit = true
                    that.formData = Object.assign({}, record)
                    that.formData.cfab0005 = new Date(record.cfab0005);
                    that.formData.cfab0006 = new Date(record.cfab0006);
                } else {
                    that.visible = false
                }
            },
            handleView(index) {
                let that = this;
                that.title = "保障标准查看"
                let record = that.tableData[index];
                if (record.id) {
                    that.visible = true
                    that.showSubmit = false
                    that.formData = Object.assign({}, record)
                    that.formData.cfab0005 = new Date(record.cfab0005);
                    that.formData.cfab0006 = new Date(record.cfab0006);
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let that = this;
                        let dataParam = {
                            id: that.formData.id,
                            cfab0001: that.formData.cfab0001,
                            cfab0002: that.formData.cfab0002,
                            cfab0003: that.formData.cfab0003,
                            cfab0004: that.formData.cfab0004,
                            cfab0005: DateFormat(that.formData.cfab0005, 'YYYY-MM-DD'),
                            cfab0006: DateFormat(that.formData.cfab0006, 'YYYY-MM-DD'),
                            cfab0009: that.formData.cfab0009,
                            cfab0010: that.formData.cfab0010
                        }
                        let url = null;
                        if (dataParam.id == null) {
                            url = that.url.add
                        } else {
                            url = that.url.edit
                        }
                        postAction(url, dataParam).then((res) => {
                            if (res.data.data.code == 1) {
                                that.visible = false
                                this.$Message.success("提交成功！")
                                this.loadData();
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '必填信息未填写完成!', desc: '必填信息未填写完成!'})
                    }
                });
            }
        },
        created() {
            this.loadData();
        },
    }
</script>
<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }
</style>
